package com.cloudptt.wp.ui.address.map.ui;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MarkerRoundMenu {
	public MapView mMapView;
	public View mView;
	protected Object mRelatedObject;
	private GeoPoint mPosition;
	public boolean mIsVisible;
	private TextView distanceView;

	public MarkerRoundMenu(int layoutResId, MapView mapView) {
		mMapView = mapView;
		mIsVisible = false;
		ViewGroup parent = (ViewGroup) mapView.getParent();
		Context context = mapView.getContext();
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mView = inflater.inflate(layoutResId, parent, false);
	}

	public MarkerRoundMenu(View v, MapView mapView) {
		mMapView = mapView;
		mView = v;
	}
	
	public View getView(){
		return mView;
	}

	public void open(Object object, Marker marker, GeoPoint position, int offsetX, int offsetY) {
		close(); // if it was already opened
		mRelatedObject = object;
		mPosition = position;
		MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
				MapView.LayoutParams.WRAP_CONTENT, mPosition, MapView.LayoutParams.TOP_CENTER, offsetX, offsetY);
		
		/*mPosition = position;
        MapView.LayoutParams lp = new MapView.LayoutParams(
            MapView.LayoutParams.WRAP_CONTENT,
            MapView.LayoutParams.WRAP_CONTENT,
            mPosition, MapView.LayoutParams.BOTTOM_CENTER,
            offsetX, offsetY);*/
		
		if (mMapView != null && mView != null) {
			mMapView.addView(mView, lp);
			mIsVisible = true;
		} else {
		}
	}

	public void close() {
		if (mIsVisible) {
			((ViewGroup) mView.getParent()).removeView(mView);
			mIsVisible = false;
		}
	}
	
	/*public TextView getDistanceTextView(){
		return distanceView;
	}
	
	public void setDistanceTextView(TextView view){
		distanceView = view;
	}*/

	public RoundMenuView getRoundMenuView() {
		// TODO Auto-generated method stub
		return null;
	}

	public View getLayout() {
		// TODO Auto-generated method stub
		return null;
	}
}
